/**	
 * <br>
 * Copyright 2011 IFlyTek. All rights reserved.<br>
 * <br>			 
 * Package: com.iflytek.utils <br>
 * FileName: StringUtils.java <br>
 * <br>
 * @version
 * @author sbwang@iflytek.com
 * @created 2013-5-29
 * @last Modified 
 * @history
 */

package com.iflytek.ci.common;

import org.apache.commons.lang.StringUtils;

/**
 * 字符处理类
 * 
 * @author sbwang@iflytek.com
 * @lastModified
 * @history
 */

public class StringUtil {

    /**
     * 
     * 替换非法字符
     * 
     * @param str
     * @return
     * @author sbwang@iflytek.com
     * @created 2013-5-29 下午09:49:10
     * @lastModified
     * @history
     */
    public static String replace(String str) {
        if (StringUtils.isNotEmpty(str)) {
            /*
             * str = str.replace("'", "''").replace("]", "]]").replace("&",
             * "chr(38)").replace("%", "chr(37)").replace("\\", "chr(92)")
             * .replace("\"", "chr(34)").replace("_", "chr(95)");
             */
            str = str.replace("'", "''").replace("%", "\\%")
                    .replace("\\", "\\\\").replace("_", "\\_");
        }
        return str;
    }
    
    /**
     * 
     *  去掉尾部全部特定字符串
     *  @param str
     *  @param removeStr
     *  @return
     *  @author xkfeng@iflytek.com
     *  @created 2013-7-19 上午09:11:30
     *  @lastModified       
     *  @history
     */
    public static String removeEndStr(String str,String removeStr){
        String str2 = StringUtils.removeEnd(str, removeStr);
        while(!str2.equals(str)){
            str = str2;
            str2 = StringUtils.removeEnd(str, removeStr);
        }
        return str2;
    }
}
